package sg.edu.nus.iss.vmcs.maintenance;

/*
 * Copyright 2011 ISS.
 * The contents contained in this document may not be reproduced in any
 * form or by any means, without the written permission of ISS, other
 * than for the purpose for which it has been supplied.
 *
 */

import java.awt.event.*;
import java.awt.*;

/**
 * This class represents control object that monitors the events in the Drink Display
 * and performs actions in response to the buttons being processed. This class implements
 * the interface ActionListener from Java AWT Event package.
 *
 * @version 1.0  07/12/2011
 * @author Team 7S - SE19
 */

public class DrinkDisplayListener implements ActionListener {

	private MaintenanceController mCtrl;

/**
 * This constructor creates an instance of the Drink Display Listener.
 * It receives the reference for the MaintenanceController object.
 * @param mctrl Maintenance Controller
 * @see MaintenanceController
 */	
	public DrinkDisplayListener(MaintenanceController mctrl) {
		mCtrl = mctrl;
	}

/**
 * Invoked when an action occurs. Implemented as a part of interface 
 * @param e ActionEvent 
 * @see MaintenanceController#displayDrinks(int)
 */	
	public void actionPerformed(ActionEvent e) {
		Button btn;
		String cmd;
		int idx;

		btn = (Button) e.getSource();
		cmd = btn.getActionCommand();
		idx = Integer.parseInt(cmd);

		mCtrl.displayDrinks(idx);
	}

}